package com.upic.serviceImpl;

import com.upic.po.Question;
import com.upic.repository.QuestionRepository;
import com.upic.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author YeTian
 * @date 2018/2/7/007
 */
@Service("questionService")
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    private QuestionRepository questionRepository;

    @Override
    public Question saveQuestion(Question question) {
        return questionRepository.save(question);
    }

    @Override
    public String deleteQuestion(long questionId) {
        questionRepository.delete(questionId);
        return "SUCCESS";
    }

    @Override
    public Page<Question> searchQuestion(Pageable pageable) {
        return questionRepository.findAll(pageable);
    }

    @Override
    public List<Question> searchQuestion() {
        return questionRepository.findAll();
    }

    @Override
    public Question findOne(long questionId) {
        return questionRepository.findOne(questionId);
    }

    @Override
    public Question updateQuestion(Question question) {
        return questionRepository.saveAndFlush(question);
    }
}
